
import pygame, sys, math

pygame.init()

from Ball import Ball
from PlayerBall import PlayerBall

clk = pygame.time.Clock()

width = 640
height = 480
size = width, height

screen = pygame.display.set_mode(size)
bgImage = pygame.image.load("background.png")
bgRect = bgImage.get_rect()

ball1 = Ball(["purple.png", "orange ball.png", "blue.png", ], (5,2), (width/2, height/2), (50,50))
ball2 = Ball(["green.png", "blue.png", "purple.png"], (2,5), (width/3, height/3), (50, 50))
ball3 = Ball(["blue.png", "green.png", "orange ball.png"], (4,7), (450, 125), (50,50))
ball4 = Ball(["orange ball.png", "purple.png", "green.png"], (8,9), (350, 125), (50, 50))

pBall = PlayerBall(["red.png"], (3,3), (500,500), (75,75))

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                pBall.direction("right")
            if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                pBall.direction("left")
            if event.key == pygame.K_w or event.key == pygame.K_UP:
                pBall.direction("up")
            if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                pBall.direction("down")
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
                pBall.direction("stop right")
            if event.key == pygame.K_a or event.key == pygame.K_LEFT:
                pBall.direction("stop left")
            if event.key == pygame.K_w or event.key == pygame.K_UP:
                pBall.direction("stop up")
            if event.key == pygame.K_s or event.key == pygame.K_DOWN:
                pBall.direction("stop down")
    
    ball1.update()
    ball2.update()
    ball3.update()
    ball4.update()
    pBall.update()
    
    
    ball1.wallBounce(width, height)
    ball2.wallBounce(width, height)
    ball3.wallBounce(width, height)
    ball4.wallBounce(width, height)
    pBall.wallBounce(width, height)
    
    
    ball1.collideBall(ball2)
    ball1.collideBall(ball3)
    ball2.collideBall(ball3)
    ball4.collideBall(ball1)
    ball4.collideBall(ball2)
    ball4.collideBall(ball3)
    
    pBall.collideBall(ball1)
    pBall.collideBall(ball2)
    pBall.collideBall(ball3)
    pBall.collideBall(ball4)
    
    
    screen.blit(bgImage, bgRect)
    
    #screen.fill(bgColor)
    screen.blit(ball1.image, ball1.rect)
    screen.blit(ball2.image, ball2.rect)
    screen.blit(ball3.image, ball3.rect)
    screen.blit(ball4.image, ball4.rect)
    screen.blit(pBall.image, pBall.rect)
    pygame.display.flip()
    clk.tick(50)
    